package com.example.entity.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum CouponStatusEnum implements BaseEnum {
    NOT_ISSUED(1, "未发放"),
    PENDING(2, "待开始"),
    ONGOING(3, "进行中"),
    ENDED(4, "已结束"),
    EXPIRED(5, "已失效");
    @EnumValue
    private final int value;
    private final String desc;

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static CouponStatusEnum of(Integer value) {
        if (value == null) {
            return null;
        }
        for (CouponStatusEnum status : values()) {
            if (status.value == value) {
                return status;
            }
        }
        return null;
    }

    public static String desc(Integer value) {
        CouponStatusEnum status = of(value);
        return status == null ? "" : status.desc;
    }
}
